package com.zp.base.controller.HisDataIcd10;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.zp.base.entity.HisDataIcd10.bo.HisDataIcd10Bo;
import com.zp.base.entity.HisDataIcd10.vo.HisDataIcd10Vo;
import com.zp.base.service.HisDataIcd10.IHisDataIcd10Service;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 数据，ICD-10编码控制器
 * 前端访问路由地址为:/base/hisDataIcd10
 *
 * @author zhang peng
 * @ date 2024-01-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hisDataIcd10")
public class HisDataIcd10Controller extends BaseController {

    private final IHisDataIcd10Service iHisDataIcd10Service;

    /**
     * 查询数据，ICD-10编码列表 (分页)
     */
    @SaCheckPermission("base:hisDataIcd10:list")
    @GetMapping("/selectPage")
    public TableDataInfo<HisDataIcd10Vo> selectPage (HisDataIcd10Bo bo, PageQuery pageQuery) {
        return iHisDataIcd10Service.queryPageList(bo, pageQuery);
    }

    /**
     * 查询数据，ICD-10编码列表 (不分页)
     */
    @SaCheckPermission("base:hisDataIcd10:list")
    @GetMapping("/list")
    public R<List<HisDataIcd10Vo>> list (HisDataIcd10Bo bo) {
        List<HisDataIcd10Vo> list = iHisDataIcd10Service.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出数据，ICD-10编码列表
     */
    @SaCheckPermission("base:hisDataIcd10:export")
    @Log(title = "数据，ICD-10编码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (HisDataIcd10Bo bo, HttpServletResponse response) {
        List<HisDataIcd10Vo> list = iHisDataIcd10Service.queryList(bo);
        ExcelUtil.exportExcel(list, "数据，ICD-10编码", HisDataIcd10Vo.class, response);
    }

    /**
     * 获取数据，ICD-10编码详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("base:hisDataIcd10:list")
    @GetMapping("/{id}")
    public R<HisDataIcd10Vo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String id) {
        return R.ok(iHisDataIcd10Service.queryById(id));
    }

    /**
     * 新增数据，ICD-10编码
     */
    @SaCheckPermission("base:hisDataIcd10:add")
    @Log(title = "数据，ICD-10编码", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody HisDataIcd10Bo bo) {
        return toAjax(iHisDataIcd10Service.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改数据，ICD-10编码
     */
    @SaCheckPermission("base:hisDataIcd10:edit")
    @Log(title = "数据，ICD-10编码", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody HisDataIcd10Bo bo) {
        return toAjax(iHisDataIcd10Service.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除数据，ICD-10编码
     *
     * @param ids 主键串
     */
    @SaCheckPermission("base:hisDataIcd10:remove")
    @Log(title = "数据，ICD-10编码", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] ids) {
        return toAjax(iHisDataIcd10Service.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * @return
     * @Author zhangpeng
     * @Description // 字典自动补全检索
     * @ date 17:54 2023/6/23
     * @Param * @param null
     **/
    @GetMapping("/getAutoHisIcd")
    public R<List<HisDataIcd10Vo>> getAutoHisIcd (HisDataIcd10Bo bo) {
        List<HisDataIcd10Vo> list = iHisDataIcd10Service.getAutoHisIcd(bo);
        return R.ok(list);
    }
}
